import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mall/screens/home/home_search_screen.dart';

import '../../components/product_list.dart';
import '../../theme.dart';

class ProductCategoryScreenArgs {
  final String name;
  final int storeId;
  final int categoryId;
  final int areaId;
  final String queryKey;

  ProductCategoryScreenArgs(
    this.name, {
    this.storeId,
    this.categoryId,
    this.areaId,
    this.queryKey,
  });
}

/// 店铺分类结果（同搜索结果）
class ProductCategoryScreen extends StatefulWidget {
  static const routeName = "/ProductCategoryScreen";
  final ProductCategoryScreenArgs args;

  const ProductCategoryScreen({
    Key key,
    @required this.args,
  }) : super(key: key);

  @override
  _ProductCategoryScreenState createState() => _ProductCategoryScreenState();
}

class _ProductCategoryScreenState extends State<ProductCategoryScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: GestureDetector(
          onTap: _onTapSearch,
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 8.w),
            height: 25.w,
            decoration: BoxDecoration(
              border: Border.all(color: kLineColor),
              borderRadius: BorderRadius.circular(12.5.w),
            ),
            child: Row(
              children: [
                Icon(Icons.search),
                Text("${widget.args.name}", style: TextStyle(fontSize: 14.sp)),
              ],
            ),
          ),
        ),
      ),
      body: ProductList(
        storeId: widget.args.storeId,
        categoryId: widget.args.categoryId,
        areaId: widget.args.areaId,
        queryKey: widget.args.queryKey,
      ),
    );
  }

  void _onTapSearch() {
    Navigator.of(context).pushNamed(
      HomeSearchScreen.routeName,
      arguments: HomeSearchScreenArgs(
        storeId: widget.args.storeId,
        categoryId: widget.args.categoryId,
        areaId: widget.args.areaId,
      ),
    );
  }
}
